package events

import "github.com/asaskevich/EventBus"

type EventTopic struct {
	Topic string
}

func (et *EventTopic) String() string {
	return et.Topic
}

type EventObject[T any] struct {
	EventName *EventTopic
	Source    T
}

var bus = EventBus.New()

func RegisterSubscribe(topic *EventTopic, listener any) error {
	return bus.Subscribe(topic.String(), listener)
}

func RegisterAsyncSubscribe(topic *EventTopic, listener any) error {
	return bus.SubscribeAsync(topic.String(), listener, false)
}

func UnregisterSubscribe(topic *EventTopic, listener any) error {
	return bus.Unsubscribe(topic.String(), listener)
}

func Publish(topic *EventTopic, args ...any) {
	bus.Publish(topic.String(), args...)
}
